package org.wgc.study.config;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/***
 *@title BatchHelloWorldJob
 *@description <TODO description class purpose>
 *@author wgc_j
 *@version 1.0.0
 *@create 2025-08-04 15:05
 **/
@Configuration
public class BatchHelloWorldJob {

    /**
     * 创建任务对象
     */
    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    /**
     * 执行任务对象
     */
    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    /**
     * 创建任务
     *
     * @return
     */
    @Bean
    public Job helloWorld() {
        return jobBuilderFactory.get("helloWorld")
                //执行step
                .start(step()).build();
    }

    @Bean
    public Step step() {
        return stepBuilderFactory.get("step").tasklet(new Tasklet() {
            @Override
            public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
                System.out.println("Hello World！");
                // 返回的状态
                return RepeatStatus.FINISHED;
            }
        }).build();
    }

    /**
     * 创建任务
     *
     * @return
     */
    @Bean
    public Job lambdaJob() {
        return jobBuilderFactory.get("lambdaJob")
                // 执行lambdaStep
                .start(lambdaStep()).build();
    }

    public Step lambdaStep() {
        return stepBuilderFactory.get("lambdaStep").tasklet((stepContribution, chunkContext) -> {
                    System.out.println("lambdaStep执行步骤....");
                    return RepeatStatus.FINISHED;
                }
        ).build();
    }


}

